package com.vonchange.utils.res;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.vonchange.utils.file.FileUtils;
import com.vonchange.utils.res.compressor.TResCompressorUtils;

public class JsUtils {
	private static Map<String,Long> jsFileCacheMap= new HashMap<String, Long>();
	public static File  toMinJs(File orgFile,File minFile){
		if(!orgFile.exists()){
			if(minFile.exists()){
				return minFile;
			}
			return null;
		}
		String path=orgFile.getAbsolutePath();
		Long lastTime=jsFileCacheMap.get(path);
		if(null==lastTime||lastTime.longValue()!=orgFile.lastModified()){
			jsFileCacheMap.put(path, orgFile.lastModified());
			//压缩
			String result = TResCompressorUtils.jsCompressorByFile(orgFile);
			if(null!=result){
				try {
					FileUtils.writeStringToFile(minFile, result);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}			
		}	
		return minFile;
	}

}
